package com.softstao.guoyu.ui.activity.agent;

import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.softstao.guoyu.R;
import com.softstao.guoyu.base.BaseActivity;
import com.softstao.guoyu.global.SharePreferenceManager;
import com.softstao.guoyu.global.UserManager;
import com.softstao.guoyu.model.agent.ShareInvite;
import com.softstao.guoyu.model.me.User;
import com.softstao.guoyu.mvp.interactor.agent.AgentInteractor;
import com.softstao.guoyu.mvp.presenter.agent.AgentPresenter;
import com.softstao.guoyu.mvp.viewer.agent.GetInviteViewer;
import com.softstao.softstaolibrary.library.model.ShareContent;
import com.softstao.softstaolibrary.library.widget.share.ShareDialog;
import com.wangjie.androidinject.annotation.annotations.mvp.AIPresenter;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by vaikus on 2017/6/30.
 */

public class InviteActivity extends BaseActivity implements GetInviteViewer{

    @AIPresenter(presenter = AgentPresenter.class, interactor = AgentInteractor.class)
    AgentPresenter presenter;

    @BindView(R.id.level)
    TextView level;
    @BindView(R.id.loading)
    RelativeLayout loading;
    private String level_name;
    private ShareInvite shareInvite;
    private ShareDialog shareDialog;

    @Override
    public int _ContentView() {
        return R.layout.activity_invite;
    }

    @Override
    public void initView() {
        initTitle("邀请经销商");
        switch (User.Type.fromInteger(UserManager.getInstance().getUser().getLevel())) {
            case ANGEL:
                level_name = "天使";
                break;
            case CROWN:
                level_name = "皇冠";
                break;
            case ONE_LEVEL:
                level_name = "一级";
                break;
            case CITY_LEVEL:
                level_name = "市级";
                break;
            case PROVINCE:
                level_name = "省代";
                break;
            case HEADQUARTER:
                level_name = "总部";
                break;
            case UNAGENT:
                level_name = "未授权";
                break;
        }
        level.setText("您目前的等级是：" + level_name);

        presenter = new AgentPresenter();
        presenter.setInteractor(new AgentInteractor());
        presenter.setViewer(this);
        getInvite();
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (shareDialog!=null){
            shareDialog.dismiss();
        }
    }

    @OnClick(R.id.share_btn)
    public void onViewClicked() {
        if (shareInvite!=null) {
            shareDialog = new ShareDialog(this, R.style.MyDialogStyle);
            ShareContent shareContent = new ShareContent();
            shareContent.imageUrl = shareInvite.getShareImg();
            String url = shareInvite.getShareUrl();
            shareContent.url = url;
            shareContent.title = "果语(GIOCOSO)---儿童零食机开创者，成为我们代理获得更多优惠！";
            shareContent.content = "赶快点击链接注册吧！";
            shareDialog.setShareContent(shareContent);
            shareDialog.show();
        }
    }

    @Override
    public void getInvite() {
        loading.setVisibility(View.VISIBLE);
        presenter.getInvite(SharePreferenceManager.getInstance().getAgentId());
    }

    @Override
    public void getResult(ShareInvite shareInvite) {
        loading.setVisibility(View.GONE);
        if (shareInvite != null) {
            this.shareInvite = shareInvite;
        }
    }

    @Override
    protected void error(String msg) {
        super.error(msg);
        loading.setVisibility(View.GONE);
    }
}
